package Logicamente;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import java.awt.GridBagLayout;

import javax.swing.JButton;

import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.Cursor;
import java.awt.Toolkit;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class VentanaProfesor extends JFrame {

	private JPanel contentPane;

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					VentanaProfesor frame = new VentanaProfesor(null);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 * @param u 
	 */
	public VentanaProfesor(final Usuario u) {
		setIconImage(Toolkit.getDefaultToolkit().getImage(VentanaProfesor.class.getResource("/Imagenes/L.png")));
		setTitle("Logicamente");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 350, 300);
		contentPane = new JPanelConFondo("/Imagenes/fondo.jpg");
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		JPanel panel = new JPanelConFondo("/Imagenes/fondo.jpg");
		contentPane.add(panel, BorderLayout.CENTER);
		GridBagLayout gbl_panel = new GridBagLayout();
		gbl_panel.columnWidths = new int[] {0, 200, 0};
		gbl_panel.rowHeights = new int[] {0, 15, 15, 15, 0};
		gbl_panel.columnWeights = new double[]{100.0, 50.0, 100.0};
		gbl_panel.rowWeights = new double[]{100.0, 10.0, 10.0, 10.0, 100.0};
		panel.setLayout(gbl_panel);
		
		JButton btnVerPartidas = new JButton("Ver partidas actuales");
		btnVerPartidas.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				actionVerPartidas(e);
			}
		});
		btnVerPartidas.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		GridBagConstraints gbc_btnVerPartidas = new GridBagConstraints();
		gbc_btnVerPartidas.fill = GridBagConstraints.BOTH;
		gbc_btnVerPartidas.insets = new Insets(0, 0, 5, 5);
		gbc_btnVerPartidas.gridx = 1;
		gbc_btnVerPartidas.gridy = 1;
		panel.add(btnVerPartidas, gbc_btnVerPartidas);
		btnVerPartidas.setToolTipText("Vea el desarrollo en tiempo real de sus alumnos");
		
		JButton btnCrearPartida = new JButton("Crear una partida");
		btnCrearPartida.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				actionCrearPartida(e,u);				
			}
		});
		btnCrearPartida.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		GridBagConstraints gbc_btnCrearPartida = new GridBagConstraints();
		gbc_btnCrearPartida.fill = GridBagConstraints.BOTH;
		gbc_btnCrearPartida.insets = new Insets(0, 0, 5, 5);
		gbc_btnCrearPartida.gridx = 1;
		gbc_btnCrearPartida.gridy = 2;
		panel.add(btnCrearPartida, gbc_btnCrearPartida);
		btnCrearPartida.setToolTipText("Permite crear un nueva partida");
		
		JButton btnAgregarPreguntas = new JButton("Agregar preguntas");
		btnAgregarPreguntas.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				actionAgregarPregunta(e);
				
			}
		});
		btnAgregarPreguntas.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		GridBagConstraints gbc_btnAgregarPreguntas = new GridBagConstraints();
		gbc_btnAgregarPreguntas.fill = GridBagConstraints.BOTH;
		gbc_btnAgregarPreguntas.insets = new Insets(0, 0, 5, 5);
		gbc_btnAgregarPreguntas.gridx = 1;
		gbc_btnAgregarPreguntas.gridy = 3;
		panel.add(btnAgregarPreguntas, gbc_btnAgregarPreguntas);
		btnAgregarPreguntas.setToolTipText("Agregue nuevas preguntas a la base de datos de Logicamente");
	}
	
	protected void actionCrearPartida(ActionEvent e, Usuario u) {
		VentanaCrearPartidaA v = new VentanaCrearPartidaA(u);
		v.setLocationRelativeTo(null);
		v.setVisible(true);			
		this.setVisible(false);
		this.hide();		
	}



	protected void actionAgregarPregunta(ActionEvent e)
	{
		VentanaAgregarPregunta v = new VentanaAgregarPregunta(this);
		v.setVisible(true);
		this.setVisible(false);
	}
	protected void actionVerPartidas(ActionEvent e)
	{
		VentanaEstadisticas v = new VentanaEstadisticas(this);
		v.setVisible(true);
		this.setVisible(false);
	}
}
